package cn.com.nes.site.service.workOrder.impl;

import cn.com.nes.common.em.WorkOrderRecordDescEnum;
import cn.com.nes.common.em.WorkOrderRecordEnum;
import cn.com.nes.common.exception.BusinessException;
import cn.com.nes.mybatis.callcenter.entity.WorkOrderRecord;
import cn.com.nes.site.entity.bo.workorder.WorkOrderBO;
import cn.com.nes.site.entity.em.DeleteEnum;
import cn.com.nes.site.entity.em.WorkOrderStautsEnum;
import cn.com.nes.site.entity.em.WorkOrderTypeEnum;
import cn.com.nes.site.service.workOrder.WorkOrderRecordService;
import cn.com.nes.site.service.workOrder.WorkOrderService;
import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 经销商
 */
@Service
public class ConsultWorkOrderBuilder extends WorkOrderBuilder {
    @Resource
    private WorkOrderService workOrderService;
    @Resource
    private WorkOrderRecordService workOrderRecordService;

    @Override
    public String getType() {
        return WorkOrderTypeEnum._3.getKey();
    }

    //空实现不做任何处理
    @Override
    protected void saveEquipmentInfo(WorkOrderBO workOrderBO) throws Exception {

    }

    @Override
    protected void validDefaultField(WorkOrderBO workOrderBO) throws BusinessException {
        if (StringUtils.isEmpty(workOrderBO.getAddress())) {
            throw new BusinessException("咨询详细地址不能为空");
        }
        if (StringUtils.isEmpty(workOrderBO.getConsultType())) {
            throw new BusinessException("咨询类别不能为空");
        }
        if (StringUtils.isEmpty(workOrderBO.getAppealContent())) {
            throw new BusinessException("咨询描述不能为空");
        }
    }
    @Override
    public String createWorkOrder(WorkOrderBO workOrderBO) throws Exception {
        Long workOrderId = workOrderService.createConsultWorkOrder(workOrderBO);
        return workOrderId.toString();
    }

    @Override
    protected void saveWorkOrderRecord(WorkOrderBO workOrderBO, String workOrderId) {
        WorkOrderRecord record = new WorkOrderRecord();
        record.setGmtCreate(workOrderBO.getOperateTimeStamp());
        record.setGmtModified(workOrderBO.getOperateTimeStamp());
        record.setIsDelete(DeleteEnum._0.getKey());
        record.setStatus(Integer.parseInt(WorkOrderStautsEnum._3.getKey()));
        record.setDesc(WorkOrderRecordEnum._3.getVal());
        record.setWorkOrderId(Long.parseLong(workOrderId));
        record.setUserId(workOrderBO.getOperateUserId());
        workOrderRecordService.saveWorkOrderRecord(record);
    }

    @Override
    protected void sendAliSms(WorkOrderBO workOrderBO) {

    }
}
